package com.ruoyi.web.controller.erp.planner;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erp.planner.domian.Planner;
import com.ruoyi.erp.planner.service.PlannerService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QiuRongYu@itcast.cn
 * @version 1.0
 * @date 2020/12/25
 */
@Controller
@RequestMapping("/planner")
public class PlannerController extends BaseController {
    private String prefix = "erp/planner";
    @Resource
    private PlannerService plannerService;
    @GetMapping()
    public String getList() {
        return prefix + "/list";
    }
    @GetMapping("/add")
    public String addList()
    {
        return prefix + "/add";
    }
    @GetMapping("/edit")
    public String edit()
    {
        return prefix + "/edit";
    }
    @RequiresPermissions("planner:planner:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Planner planner)
    {
        List<Planner> plannerList = plannerService.export(planner);
        ExcelUtil<Planner> util = new ExcelUtil<>(Planner.class);
        return util.exportExcel(plannerList, "计划人数据");
    }

    /**
     * 根据id删除
     */
    @RequiresPermissions("planner:planner:remove")
    @PostMapping("/remove")
    @ResponseBody
    public  AjaxResult remove(String ids){
        plannerService.remove(ids);
        return AjaxResult.success("删除成功");
    }
    /**
     * 修改运输方式代码
     */
    @RequiresPermissions("planner:planner:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editplanner(Planner planner) {
        plannerService.editplanner(planner);
        return AjaxResult.success("修改成功");
    }
    /**
     * 根据id查询详情
     */
    @GetMapping("/edit/{id}")
    public String plannerselect(@PathVariable("id") String buyerCode, ModelMap mmap) {
        Planner planner=plannerService.plannerselect(buyerCode);
        mmap.put("planner", planner);
        return prefix + "/edit";
    }

    /**
     * 新增计划人
     * @param planner
     * @return
     */
    @RequiresPermissions("planner:planner:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult plannerAdd(Planner planner){
         plannerService.plannerAdd(planner);
         return AjaxResult.success("添加成功");
    }
    /**
     * 查询计划人列表
     * @param planner
     * @return
     */
    @ApiOperation(value="查询列表")
    @PostMapping("/plannerList")
    @ResponseBody
    public TableDataInfo plannerList(Planner planner){
      List<Planner>list= plannerService.plannerList(planner);
      return getDataTable(list);
    }
}
